package com.mobile.collect.db;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.mobile.collect.beans.ExportResultInfo;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "EXPORT_RESULT_INFO".
*/
public class ExportResultInfoDao extends AbstractDao<ExportResultInfo, Long> {

    public static final String TABLENAME = "EXPORT_RESULT_INFO";

    /**
     * Properties of entity ExportResultInfo.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property _ID = new Property(0, Long.class, "_ID", true, "_id");
        public final static Property DeviceName = new Property(1, String.class, "deviceName", false, "DEVICE_NAME");
        public final static Property DeviceNum = new Property(2, String.class, "deviceNum", false, "DEVICE_NUM");
        public final static Property DevicePic = new Property(3, String.class, "devicePic", false, "DEVICE_PIC");
        public final static Property ParentId = new Property(4, Long.class, "parentId", false, "PARENT_ID");
        public final static Property ExportTime = new Property(5, String.class, "exportTime", false, "EXPORT_TIME");
        public final static Property HadUploaded = new Property(6, boolean.class, "hadUploaded", false, "HAD_UPLOADED");
        public final static Property ExcelPath = new Property(7, String.class, "excelPath", false, "EXCEL_PATH");
    }

    private DaoSession daoSession;

    private Query<ExportResultInfo> exportInfo_ResultInfosQuery;

    public ExportResultInfoDao(DaoConfig config) {
        super(config);
    }
    
    public ExportResultInfoDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"EXPORT_RESULT_INFO\" (" + //
                "\"_id\" INTEGER PRIMARY KEY ," + // 0: _ID
                "\"DEVICE_NAME\" TEXT," + // 1: deviceName
                "\"DEVICE_NUM\" TEXT," + // 2: deviceNum
                "\"DEVICE_PIC\" TEXT," + // 3: devicePic
                "\"PARENT_ID\" INTEGER," + // 4: parentId
                "\"EXPORT_TIME\" TEXT," + // 5: exportTime
                "\"HAD_UPLOADED\" INTEGER NOT NULL ," + // 6: hadUploaded
                "\"EXCEL_PATH\" TEXT);"); // 7: excelPath
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"EXPORT_RESULT_INFO\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, ExportResultInfo entity) {
        stmt.clearBindings();
 
        Long _ID = entity.get_ID();
        if (_ID != null) {
            stmt.bindLong(1, _ID);
        }
 
        String deviceName = entity.getDeviceName();
        if (deviceName != null) {
            stmt.bindString(2, deviceName);
        }
 
        String deviceNum = entity.getDeviceNum();
        if (deviceNum != null) {
            stmt.bindString(3, deviceNum);
        }
 
        String devicePic = entity.getDevicePic();
        if (devicePic != null) {
            stmt.bindString(4, devicePic);
        }
 
        Long parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindLong(5, parentId);
        }
 
        String exportTime = entity.getExportTime();
        if (exportTime != null) {
            stmt.bindString(6, exportTime);
        }
        stmt.bindLong(7, entity.getHadUploaded() ? 1L: 0L);
 
        String excelPath = entity.getExcelPath();
        if (excelPath != null) {
            stmt.bindString(8, excelPath);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, ExportResultInfo entity) {
        stmt.clearBindings();
 
        Long _ID = entity.get_ID();
        if (_ID != null) {
            stmt.bindLong(1, _ID);
        }
 
        String deviceName = entity.getDeviceName();
        if (deviceName != null) {
            stmt.bindString(2, deviceName);
        }
 
        String deviceNum = entity.getDeviceNum();
        if (deviceNum != null) {
            stmt.bindString(3, deviceNum);
        }
 
        String devicePic = entity.getDevicePic();
        if (devicePic != null) {
            stmt.bindString(4, devicePic);
        }
 
        Long parentId = entity.getParentId();
        if (parentId != null) {
            stmt.bindLong(5, parentId);
        }
 
        String exportTime = entity.getExportTime();
        if (exportTime != null) {
            stmt.bindString(6, exportTime);
        }
        stmt.bindLong(7, entity.getHadUploaded() ? 1L: 0L);
 
        String excelPath = entity.getExcelPath();
        if (excelPath != null) {
            stmt.bindString(8, excelPath);
        }
    }

    @Override
    protected final void attachEntity(ExportResultInfo entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public ExportResultInfo readEntity(Cursor cursor, int offset) {
        ExportResultInfo entity = new ExportResultInfo( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // _ID
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // deviceName
            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // deviceNum
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // devicePic
            cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4), // parentId
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // exportTime
            cursor.getShort(offset + 6) != 0, // hadUploaded
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7) // excelPath
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, ExportResultInfo entity, int offset) {
        entity.set_ID(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setDeviceName(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setDeviceNum(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
        entity.setDevicePic(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setParentId(cursor.isNull(offset + 4) ? null : cursor.getLong(offset + 4));
        entity.setExportTime(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setHadUploaded(cursor.getShort(offset + 6) != 0);
        entity.setExcelPath(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(ExportResultInfo entity, long rowId) {
        entity.set_ID(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(ExportResultInfo entity) {
        if(entity != null) {
            return entity.get_ID();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(ExportResultInfo entity) {
        return entity.get_ID() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "resultInfos" to-many relationship of ExportInfo. */
    public List<ExportResultInfo> _queryExportInfo_ResultInfos(Long parentId) {
        synchronized (this) {
            if (exportInfo_ResultInfosQuery == null) {
                QueryBuilder<ExportResultInfo> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.ParentId.eq(null));
                exportInfo_ResultInfosQuery = queryBuilder.build();
            }
        }
        Query<ExportResultInfo> query = exportInfo_ResultInfosQuery.forCurrentThread();
        query.setParameter(0, parentId);
        return query.list();
    }

}
